package com.kantboot.system.dict.web.controller;

import com.kantboot.system.dict.domain.entity.SysDict;
import com.kantboot.system.dict.service.ISysDictService;
import com.kantboot.util.common.result.RestResult;
import com.kantboot.util.core.param.PageParam;
import com.kantboot.util.core.result.PageResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 系统字典控制层
 */
@RestController
@RequestMapping("/system-dict-web/dict")
public class SysDictController {

    @Resource
    private ISysDictService service;

    /**
     * 根据分组获取所有设置，以map形式返回
     * @param groupCode 分组编码
     * @return 所有设置
     */
    @RequestMapping("/getMapByGroupCode")
    public RestResult<HashMap<String,String>> getMapByGroupCode(
            @RequestParam("groupCode") String groupCode){
        return RestResult.success(service.getMapByGroupCode(groupCode),"getSuccess","获取成功");
    }

    /**
     * 根据分组和编码获取值
     * @param groupCode 分组编码
     * @param code 编码
     * @return 设置
     */
    @RequestMapping("/getValue")
    public RestResult<String> getValue(
            @RequestParam("groupCode") String groupCode,
            @RequestParam("code") String code){
        return RestResult.success(service.getValue(groupCode,code),"getSuccess","获取成功");
    }

    /**
     * 获取分组
     */
    @RequestMapping("/getBodyData")
    public RestResult<PageResult> getBodyData(@RequestBody PageParam<SysDict> pageParam){
        return RestResult.success(service.getBodyData(pageParam),"getSuccess","获取成功");
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RestResult<SysDict> save(@RequestBody SysDict entity){
        return RestResult.success(service.save(entity),"saveSuccess","保存成功");
    }

}
